package com.neuedu.nep.controller;

import com.neuedu.nep.base.BaseController;
import com.neuedu.nep.base.R;
import com.neuedu.nep.dto.AdminSignInDTO;
import com.neuedu.nep.dto.SupervisorSignInDTO;
import com.neuedu.nep.model.Admin;
import com.neuedu.nep.model.Supervisor;
import com.neuedu.nep.service.AdminService;
import com.neuedu.nep.util.JwtUtil;
import com.neuedu.nep.vo.UserVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 黄宇佳
 * @create 2024-04-12 11:35
 * @description:
 */
@RestController
@CrossOrigin
@RequestMapping("admin")
public class AdminController extends BaseController {
    @Resource
    private AdminService adminService;

    @PostMapping("SignIn")
    public R SignIn(@RequestBody AdminSignInDTO adminSignInDTO){
        String adminCode=adminSignInDTO.getAdminCode();
        String password=adminSignInDTO.getPassword();
        Admin admin = adminService.SignIn(adminCode,password);
        if (admin==null){
            return R.error("手机号/密码错误");
        }
        admin.setPassword(null);
        UserVO userVO=new UserVO();
        userVO.setRole(2);
        userVO.setAdminId(admin.getAdminId());
        String token = JwtUtil.newToken(userVO);
        return R.ok("登陆成功")
                .setResult("admin",admin)
                .setResult("token",token);
    }
}
